package com.tony.demo.ui.performance;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tony.demo.R;
import com.tony.demo.mvp.presenter.interfaces.IBasePresenter;
import com.tony.demo.ui.BaseFragment;
import com.tony.demo.ui.performance.image.BigImageActivity;
import com.tony.demo.ui.performance.image.LoadImageActivity;
import com.tony.demo.ui.performance.xnyh.draw.DrawAndLayoutActivity;
import com.tony.demo.ui.widgets.ScanningActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 发现
 */
public class PerformanceOptimizeFragment extends BaseFragment {
    ListView listView;

    List<String> list = new ArrayList<>();

    @Override
    public IBasePresenter createPresenter() {
        return null;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }

    protected void initData() {
        listView = mView.findViewById(R.id.list_view);

        list.add("在子线程创建Handler");
        list.add("加载图片，bitmap优化");
        list.add("绘制、布局优化");
        list.add("自定义控件");
        listView.setAdapter(new ArrayAdapter<>(mView.getContext(), android.R.layout.simple_list_item_1, list));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PerformanceOptimizeFragment.this.onItemClick((String) parent.getAdapter().getItem(position));
            }
        });
    }

    @Override
    protected int getViewLayout() {
        return R.layout.fragment_performance_optimize;
    }

    private void onItemClick(String item) {
        switch (item) {
            case "在子线程创建Handler":
                startActivity(ScanningActivity.class);
                break;
            case "加载图片，bitmap优化":
                startActivity(LoadImageActivity.class);
                break;
            case "绘制、布局优化":
                startActivity(DrawAndLayoutActivity.class);
                break;
            case "加载长图":
                startActivity(BigImageActivity.class);
                break;
        }
    }

}
